
package lichen.pages.control.friendList;

import lichen.entities.user.FriendList;
import lichen.pages.Operations;
import lichen.pages.base.AbstractControlPage;
import lichen.services.UserService;

import org.apache.tapestry.annotations.Component;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.annotations.InjectPage;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.corelib.components.Form;
import org.apache.tapestry.corelib.components.TextField;


/**
 * 好友列表.
 * @author <a href=mailto:xiafei114@gmail.com>xiafei114</a>
 * @version $Revision$
 * @since 0.0.3
 */
public class FormFriendList extends AbstractControlPage {
	
//	 当前的操作.
	private String action;
	
	Object onActionFromFriendForm(){
		FriendList friend = this.getFriendList();
		friend.setUser(getUser());
		this.getEntityService().saveOrUpdate(friend);
		return viewFriendList;
	}
	
	@Component(parameters={"value=friendList.friendEmail","validate=required,email"})
	private TextField friendEmail;
	
	
	@InjectPage
	private ViewFriendList viewFriendList;
	
	@Inject
	private UserService _userService;
	
	@Persist
	private FriendList friendList;
	
	void onActivate(){
		if(friendList == null)
			this.friendList = new FriendList();
	}
	
	void onActivate(String action, FriendList friendList) {
		this.action = action;
		
		if (Operations.EDIT.equals(action)) {
			this.friendList = friendList;
		} else if (Operations.NEW.equals(action)) {
			this.friendList = new FriendList();
		}
	}
	
	/**
	 * @return Returns the friendList.
	 */
	public FriendList getFriendList() {
		return friendList;
	}

	/**
	 * @param friendList The friendList to set.
	 */
	public void setFriendList(FriendList friendList) {
		this.friendList = friendList;
	}



	protected UserService getUserService(){
		return _userService;
	}
	
	@Component
    private Form friendForm;
}
